package thread;

import java.util.Scanner;

public class Demo26 {
    public static Object locker = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("t1 wait 之前");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1 wait 之后");
        });
        Thread t2 = new Thread(() -> {
            System.out.println("t2 wait 之前");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t2 wait 之后");
        });
        Thread t3 = new Thread(() -> {
            System.out.println("t3 wait 之前");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t3 wait 之后");
        });
        Thread t4 = new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("t4 notify 之前");
            scanner.next();
            synchronized (locker) {
//                locker.notifyAll();
                locker.notify();
                locker.notify();
            }
            System.out.println("t4 notify 之后");
        });
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
